const fetch = require('node-fetch');
const {
    loginAuth,
} = require('../middlewares/authorization');
const report = require('../business/report');

module.exports = router => {
    router.post('/ratings', (req, res) => {
        report.ratings().then(ratings => res.toApiJson(ratings)).catch(err => { throw err });
    });

    router.post('/fake', (req, res) => {
        fake().then(() => res.toApiJson({})).catch(err => {throw err});
    });
}

function fake(i) {
    return Promise((resolve, reject) => {
        fetch(`http://139.199.79.230/eb/user/sms`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'User-Agent': 'hongyu-test'
            },
            body: `mobile=${13110586866 + i}`//13381929000
        }).then(response => response.json()).then(result => {
            console.log(i + ':>>>:' + JSON.stringify(result));
            resolve();
        }).catch(err => {
            reject(err);
        });
    });
}